package com.ajie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.ajie.entity.SysPermission;
import com.ajie.mapper.SysPermissionMapper;
import com.ajie.service.SysPermissionService;

import java.util.List;

/**
 * 权限表;(sys_permission)表服务实现类
 * @author: ajie
 * @date : 2024-7-13
 */
@Service
public class SysPermissionServiceImpl extends ServiceImpl<SysPermissionMapper, SysPermission> implements SysPermissionService {
    @Override
    public void tree(List<SysPermission> records) {
        for (SysPermission record : records) {
            record.setLabel(record.getName());
            record.setValue(record.getId());
            LambdaQueryWrapper<SysPermission> lqw = new LambdaQueryWrapper<>();
            lqw.eq(SysPermission::getParentId, record.getId());
            lqw.orderByAsc(SysPermission::getSort);
            List<SysPermission> list = super.list(lqw);
            if (!list.isEmpty()) {
                record.setChildren(list);
                // 递归查询子级并装载到children字段中
                tree(list);
            }
        }
    }
}